Skip to content

Send IntEnum numbers as their value - #532

Open
RayBB wants to merge 5 commits into
aio-libs:masterfrom
RayBB:fix/numbers-decimal
Open

RayBB wants to merge 5 commits into
aio-libs:masterfrom
RayBB:fix/numbers-decimal

Conversation

@RayBB

@RayBB RayBB commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Numbers in request lines are formatted with %a, which is repr(). For a plain int that's the same, but an IntEnum or IntFlag gets sent as its repr, so this fails:

class TTL(enum.IntEnum):
    HOUR = 3600

await mc.set(b"key", b"value", exptime=TTL.HOUR)
# ClientException: ('stats set failed', bytearray(b'CLIENT_ERROR bad command line format'))

The same happens for a flag handler that returns an IntFlag, the touch() exptime and the incr()/decr() delta. This changes the 4 places to %d, which sends the value.

Not in a release yet: 0.8.2 used str(), which is the number on Python 3.11+.

Numbers in request lines were formatted with %a, which is repr(), so an
IntEnum exptime or an IntFlag from a flag handler was sent as e.g.
<TTL.HOUR: 3600> and memcached rejected the command. Use %d.
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.41%. Comparing base (4fae7e8) to head (3569e55).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #532      +/-   ##
==========================================
+ Coverage   98.37%   98.41%   +0.04%     
==========================================
  Files          10       10              
  Lines        1229     1261      +32     
  Branches       65       65              
==========================================
+ Hits         1209     1241      +32     
  Misses         12       12              
  Partials        8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The PR appears safe to merge.

Reviews (3) · Last reviewed commit: "Merge master" · Reviewed by Greptile

Comment thread aiomcache/client.py Resolved
Comment thread tests/commands_test.py Resolved
%d truncates a float, so incr(key, 2.5) would add 2. Pass the cas token,
flags and delta through operator.index(), which keeps IntEnum and IntFlag
working and raises ValidationException for anything else.
Comment thread aiomcache/client.py Outdated
_SetFlagHandler = Callable[[_T], Awaitable[tuple[bytes, int]]]


def _int(value: object, name: str) -> int:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything we pass to it is typed as int, so this should fix the type error:

Suggested change
def _int(value: object, name: str) -> int:
def _int(value: int, name: str) -> int:

Comment thread aiomcache/client.py Outdated
_SetFlagHandler = Callable[[_T], Awaitable[tuple[bytes, int]]]


def _int(value: object, name: str) -> int:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate name parameter feels a little awkward to me, I'd probably drop it and let the traceback handle it..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dreamsorcerer Done, both applied in 1f4c4b2, and merged master to fix the conflict.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants